package llk.datas
{
	import flash.utils.Dictionary;
	
	import llk.GameModel;
	import llk.config.Level;
	import llk.datas.vo.ItemVO;
	
	public class ItemListData
	{
		private var _itemList : Array = GameModel.getInstance( ).itemList;
		private var _tempDic:Dictionary = new Dictionary();
		public var _tempType:Array = [];
		public function ItemListData ( )
		{
		}
		
		public function generateDate():void{
			//根据ID数生成type
			generateType();
			//生成list
			generateList();
			//生成ID
			generateID();
		}
		private function generateType():void{
			var typeCount:int
			var obj:Object = Level.level
			for(var i:int = 0;i<Level.ROW;i++){
				for(var j:int = 0;j<Level.COL;j++){
					if(obj[1].idList[i][j] == 1){
						typeCount++
					}
				}
			}
			var len:int = typeCount/2
			for(var m:int = 0;m<len;m++){
				var tempType:int =  int(Level.level[1].typeCount*Math.random())+1;
				_tempType.push(tempType);
				_tempType.push(tempType);
			}
			for(var n:int = 0;n<len*2;n++){
				var tempIndex:int = int(Math.random()*len*2)
				var tempRandom:int = _tempType[n];
				_tempType[n] = _tempType[tempIndex]
				_tempType[tempIndex] = tempRandom;
			}
		}
		
		private function generateList():void{
			for(var i:int = 0;i<Level.ROW;i++){
				var temp:Array = []
				for(var j:int = 0;j<Level.COL;j++){
					var vo:ItemVO = new ItemVO;
					vo.type = int(Level.level[1].typeCount*Math.random())+1;
					vo.row = i;
					vo.col = j;
					temp.push(vo);
				}
				_itemList.push(temp);
			}
		}
		
		private function generateID():void{
			var obj:Object = Level.level;
			var tempArr:Array = obj[1].idList;
			for(var i:int = 0;i<Level.ROW;i++){
				for(var j:int = 0;j<Level.COL;j++){
					(_itemList[i][j] as ItemVO).id = tempArr[i][j];
					if(tempArr[i][j] == 1){
						(_itemList[i][j] as ItemVO).type = _tempType[0];
						_tempType.shift();
					}else{
						(_itemList[i][j] as ItemVO).type = 0;
					}
				}
			}
		}
	}
}